package org.loofer.uiframework.navigator;

import java.util.regex.Pattern;

public final class NavigatorConfig {
    private static final String APP_URL_FORMAT = "://(\\w+)/(\\w+)\\??(.*)?";
    private static final String DEFAULT_HTTP_SCHEMA = "http";
    private static final Pattern HTTP_URL_PATTERN = Pattern.compile("http://(.*):?(\\d+)?/(\\w+)/(\\w+)\\??(.*)?");
    private static final Pattern OUT_HTTP_URL_PATTERN = Pattern.compile("^(http|https|ftp)://.*$");
    private static NavigatorConfig sConfig;
    private Pattern mAppPattern;
    private String mAppSchema;

    private NavigatorConfig() {
        this.mAppPattern = null;
        this.mAppSchema = "morecruit";
        this.mAppPattern = Pattern.compile(this.mAppSchema + APP_URL_FORMAT);
    }

    public static NavigatorConfig instance() {
        if (sConfig == null) {
            synchronized (NavigatorConfig.class) {
                if (sConfig == null) {
                    sConfig = new NavigatorConfig();
                }
            }
        }
        return sConfig;
    }

    public void setAppSchema(String appSchema) {
        this.mAppSchema = appSchema;
        this.mAppPattern = Pattern.compile(this.mAppSchema + APP_URL_FORMAT);
    }

    protected String getAppSchema() {
        return this.mAppSchema;
    }

    protected String getDefaultHttpSchema() {
        return DEFAULT_HTTP_SCHEMA;
    }

    protected Pattern getHttpUrlPattern() {
        return HTTP_URL_PATTERN;
    }

    public Pattern getOutHttpUrlPattern() {
        return OUT_HTTP_URL_PATTERN;
    }

    protected Pattern getAppUrlPattern() {
        return this.mAppPattern;
    }
}
